<template>
  <div>
    <el-upload
      list-type="picture-card"
      action="#"
      :auto-upload="false"
      :on-preview="preview"
      :limit="limit"
      :file-list="fileList"
      :class="{hide:limit===fileList.length}"
      :on-change="handleChange"
      :on-remove="handleRemove"
    >
      <i class="el-icon-plus" />
    </el-upload>
    <el-dialog :visible.sync="visible" title="预览">
      <img :src="src" alt="" style="width:80%; margin:0 auto; display:block">
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    limit: {
      type: Number,
      default: 1
    }
  },
  list: {
    type: Array,
    default: () => []
  },
  data() {
    return {
      src: '',
      visible: false,
      fileList: []
    }
  },
  methods: {
    preview(file) {
      this.visible = true
      this.src = file.url
    },
    handleChange(file, fileList) {
      this.fileList = fileList
    },
    handleRemove(file, fileList) {
      this.fileList = fileList
    }
  }
}
</script>
<style scoped lang="scss">
  ::v-deep .hide .el-upload--picture-card{
  display: none;
}
</style>
